
#访问自己内网时的代码

import urllib.request

def auth_nw():

    #1.用户名
    user= 'admin'
    pwd = 'admin123'
    nei_url = "http://192.168.20.49"

    #2.创建密码管理器
    pwd_handler = urllib.request.HTTPPasswordMgrWithDefaultRealm()
    pwd_handler.add_password(None,nei_url,user,pwd)

    #3.创建认证处理器
    auth_handler = urllib.request.HTTPBasicAuthHandler(pwd_handler)

    opener = urllib.request.build_opener(auth_handler)

    response = opener.open(nei_url)
    print(response)

auth_nw()